home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CIFTP / FTPEXP / files.bas < prev    next >
Encoding:
BASIC Source File  |  2000-09-07  |  9.5 KB  |  264 lines

  1. Attribute VB_Name = "FileSystem"
  2. '--------------------------------------------------------
  3. '<Purpose> provides support for the local file system
  4. '--------------------------------------------------------
  5.  
  6. Option Explicit
  7.  
  8. '----------------------------------------------------------------
  9. '<Purpose> returns the appropriate image number for a drive type
  10. '----------------------------------------------------------------
  11. Public Function GetDriveImage(DriveLetter As String) As Integer
  12.     Dim LegalDrive As String
  13.     
  14.     LegalDrive = DriveLetter & ":\"
  15.     
  16.     '---- some drives are not supported here
  17.     Select Case GetDriveType(LegalDrive)
  18.         Case DRIVE_CDROM
  19.             GetDriveImage = imgCDRom
  20.         Case DRIVE_FIXED
  21.             GetDriveImage = imgDriveNotShared
  22.         Case DRIVE_REMOTE
  23.             GetDriveImage = imgNetDrive
  24.         Case DRIVE_REMOVABLE
  25.             GetDriveImage = imgFloppyDrive
  26.         Case Else
  27.             GetDriveImage = DRIVE_UNIDENTIFIED
  28.     End Select
  29.     
  30. End Function
  31.  
  32. '------------------------------------------------------------
  33. '<Purpose> removes a recently disconnected network drive
  34. '------------------------------------------------------------
  35. Public Sub RemoveNetDrive(ThisExplorer As Form, ParentNode As Node)
  36.     Dim WorkingNode     As Node
  37.     Dim i               As Integer
  38.     Dim DriveImage      As Integer
  39.     Dim NumberChildren  As Integer
  40.     Dim DriveLetter     As String * 1
  41.     
  42.     NumberChildren = ParentNode.Children
  43.     For i = 1 To NumberChildren
  44.         If (i = 1) Then
  45.             Set WorkingNode = ParentNode.Child
  46.         Else
  47.             Set WorkingNode = WorkingNode.Next
  48.         End If
  49.     
  50.         '---- calculate the drive letter
  51.         DriveLetter = Mid(WorkingNode.Text, 2, 1)
  52.         DriveImage = GetDriveImage(DriveLetter)
  53.         
  54.         '---- see if the drive is unidentified, and remove it
  55.         If (DriveImage = DRIVE_UNIDENTIFIED) Then
  56.             Call ThisExplorer.Tree.Nodes.Remove(WorkingNode.Key)
  57.             
  58.             '---- also remove the extra data
  59.             Call ThisExplorer.Attachments.Remove(WorkingNode.Key)
  60.             
  61.             Exit Sub
  62.         End If
  63.     Next
  64.     
  65.     Set WorkingNode = Nothing
  66. End Sub
  67.  
  68. '------------------------------------------------------------
  69. '<Purpose> populates the ListView with local files
  70. ' under a directory
  71. '------------------------------------------------------------
  72. Public Sub AddLocalFiles(ThisExplorer As Form, ParentNode As Node)
  73.     Dim TheseItems      As ListItems
  74.     Dim WorkingItem     As ListItem
  75.     Dim FileAttr        As Integer
  76.     Dim FileName        As String
  77.     Dim FileType        As String
  78.     Dim FullPathName    As String
  79.     Dim StartingDir     As String
  80.  
  81.     ThisExplorer.MousePointer = vbArrowHourglass
  82.     
  83.     On Error GoTo BadItem
  84.     
  85.     '---- cache the ListItems collection
  86.     Set TheseItems = ThisExplorer.List.ListItems
  87.             
  88.     StartingDir = ThisExplorer.Attachments(ParentNode.Key).DrivePath
  89.     
  90.     On Error GoTo Cleanup
  91.     FileName = Dir(StartingDir)
  92.     On Error GoTo BadItem
  93.  
  94.     Do While (FileName <> "")
  95.         If ((FileName <> ".") And (FileName <> "..")) Then
  96.             FullPathName = StartingDir & FileName
  97.             
  98.             FileAttr = GetAttr(FullPathName)            ' Get Files Attributes...
  99.             If (FileAttr <> vbDirectory) Then
  100.                 '---- add file to ListView
  101.                 Set WorkingItem = TheseItems.Add(, FullPathName, FileName, imgLocalFile, imgLocalFile)
  102.                 FileType = "File"
  103.             Else
  104.                 '---- add directory to ListView
  105.                 Set WorkingItem = TheseItems.Add(, FullPathName, FileName, imgFolderClosed, imgFolderClosed)
  106.                 FileType = "File Folder"
  107.             End If
  108.             
  109.             '---  add type, size, and modified bits
  110.             WorkingItem.SubItems(1) = Str((FileLen(FullPathName) \ 1024) + 1) & "KB"
  111.             WorkingItem.SubItems(2) = FileType
  112.             WorkingItem.SubItems(3) = Format(FileDateTime(FullPathName), "General Date")
  113.         End If
  114.         
  115. NextDir:
  116.         '---- dir with no arguments gets next file, or directory
  117.         FileName = Dir
  118.     Loop
  119.  
  120. Cleanup:
  121.     On Error GoTo 0
  122.     Set TheseItems = Nothing
  123.     Set WorkingItem = Nothing
  124.     ThisExplorer.MousePointer = vbDefault
  125.     Exit Sub
  126.     
  127. BadItem:
  128.     Resume NextDir
  129.     
  130. End Sub
  131.  
  132. '------------------------------------------------------------
  133. '<Purpose> populates the TreeView with local directories
  134. ' under a particular drive or directory
  135. '------------------------------------------------------------
  136. Public Sub AddLocalDirs(ThisExplorer As Form, ParentNode As Node)
  137.     Dim TheseItems      As ListItems
  138.     Dim WorkingItem     As ListItem
  139.     Dim WorkingNode     As Node
  140.     Dim TheseNodes      As Nodes
  141.     Dim FileAttr        As Integer
  142.     Dim DirName         As String
  143.     Dim FullPathName    As String
  144.     Dim NodeKey         As String
  145.     Dim StartingDir     As String
  146.     
  147.     ThisExplorer.MousePointer = vbArrowHourglass
  148.     
  149.     On Error GoTo BadNode
  150.     
  151.     '---- cache nodes and list items collections
  152.     Set TheseNodes = ThisExplorer.Tree.Nodes
  153.     Set TheseItems = ThisExplorer.List.ListItems
  154.     
  155.     TheseItems.Clear
  156.     
  157.     StartingDir = ThisExplorer.Attachments(ParentNode.Key).DrivePath
  158.     
  159.     '---- get all directories under the starting directory
  160.     DirName = Dir(StartingDir, vbDirectory)
  161.     Do While (DirName <> "")
  162.         '---- ignore current and previous directories
  163.         If ((DirName <> ".") And (DirName <> "..")) Then
  164.             FullPathName = StartingDir & DirName
  165.             FileAttr = GetAttr(FullPathName)
  166.             If (FileAttr = vbDirectory) Then
  167.                 NodeKey = ParentNode.Key & "." & DirName
  168.                 
  169.                 If (Not IsKeyed(TheseNodes, NodeKey)) Then
  170.                     '---- add the node to the tree
  171.                     Set WorkingNode = TheseNodes.Add(ParentNode, tvwChild, NodeKey, DirName, imgFolderClosed, imgFolderOpen)
  172.                 
  173.                     '---- also create and add attachment
  174.                     Dim ThisAttachment As New Attachment
  175.                     ThisAttachment.NodeType = nodLocalDrive
  176.                     ThisAttachment.DrivePath = StartingDir & DirName & "\"
  177.                     Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  178.                     Set ThisAttachment = Nothing
  179.                     
  180.                     '---- add searching placeholder
  181.                     Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  182.                 End If
  183.                 
  184.                 '---- add directory to ListView; pad with invisible char for sorting purposes
  185.                 Set WorkingItem = TheseItems.Add(, NodeKey, Chr(160) & DirName, imgFolderClosed, imgFolderClosed)
  186.                 '---  add type, size, and modified bits to item
  187.                 'WorkingItem.SubItems(1) = Str(FileLen(FullPathName) \ 1024) & "KB"
  188.                 WorkingItem.SubItems(2) = "File Folder"
  189.                 WorkingItem.SubItems(3) = Format(FileDateTime(FullPathName), "General Date")
  190.             End If
  191.         End If
  192.         '---- dir with no arguments gets next file, or directory
  193.         DirName = Dir
  194.     Loop
  195.     
  196. Cleanup:
  197.     On Error GoTo 0
  198.     Set TheseItems = Nothing
  199.     Set TheseNodes = Nothing
  200.     Set WorkingItem = Nothing
  201.     Set WorkingNode = Nothing
  202.     ThisExplorer.MousePointer = vbDefault
  203.     Exit Sub
  204.     
  205. BadNode:
  206.     GoTo Cleanup
  207. End Sub
  208.  
  209. '------------------------------------------------------------
  210. '<Purpose> populates the TreeView with local drives
  211. '------------------------------------------------------------
  212. Public Sub AddLocalDrives(ThisExplorer As Form, ParentNode As Node)
  213.     Dim DriveImage      As Integer
  214.     Dim DriveID         As Long
  215.     Dim TheseNodes      As Nodes
  216.     Dim WorkingNode     As Node
  217.     Dim DriveLetter     As String * 1
  218.     Dim NodeKey         As String
  219.     Dim ParentKey       As String
  220.     
  221.     ThisExplorer.MousePointer = vbArrowHourglass
  222.     
  223.     '---- errors can be generated from duplicate keys; ignore
  224.     On Error Resume Next
  225.     
  226.     '---- cache nodes collection
  227.     Set TheseNodes = ThisExplorer.Tree.Nodes
  228.     
  229.     ParentKey = ParentNode.Key & "."
  230.     
  231.     For DriveID = Asc("A") To Asc("Z")
  232.         DriveLetter = Chr(DriveID)
  233.         NodeKey = ParentKey & DriveLetter
  234.         
  235.         If (Not IsKeyed(TheseNodes, NodeKey)) Then
  236.             DriveImage = GetDriveImage(DriveLetter)
  237.             
  238.             If (Not (DriveImage = DRIVE_UNIDENTIFIED)) Then
  239.                 '---- add the node to the tree
  240.                 Set WorkingNode = TheseNodes.Add(ParentNode, tvwChild, NodeKey, "(" & DriveLetter & ":" & ")", DriveImage)
  241.                 
  242.                 '---- also create and add attachment
  243.                 Dim ThisAttachment As New Attachment
  244.                 ThisAttachment.NodeType = nodLocalDrive
  245.                 ThisAttachment.DrivePath = DriveLetter & ":\"
  246.                 Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  247.                 Set ThisAttachment = Nothing
  248.                                 
  249.                 '---- add searching placeholder
  250.                 Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  251.             End If
  252.         End If
  253.         
  254.     Next DriveID
  255.     
  256. Cleanup:
  257.     On Error GoTo 0
  258.     Set TheseNodes = Nothing
  259.     Set WorkingNode = Nothing
  260.     ThisExplorer.MousePointer = vbDefault
  261. End Sub
  262.  
  263.  
  264.